package ${controllerPackage};

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import ${pojoFullName};
import ${servicePackage}.${service};
import org.springframework.web.bind.annotation.*;


@RequestMapping("/${pojo?replace("Tb","")?lower_case}")
@RestController
public class ${controller}{

    private ${service} ${pojo?replace("Tb","")?lower_case}Service;

    /**
    * 新增
    * @param  实体
    * @return 操作结果
    */
    @PostMapping("/add")
    public void add(@RequestBody ${pojo} ${pojo?replace("Tb","")?lower_case}){
        try {
            ${pojo?replace("Tb","")?lower_case}Service.add(${pojo?replace("Tb","")?lower_case});
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
    * 根据主键查询
    * @param id 主键
    * @return 实体
    */
    @GetMapping("/findOne/{id}")
    public ${pojo} findOne(@PathVariable String id){
        return ${pojo?replace("Tb","")?lower_case}Service.findOne(id);
    }

    /**
    * 修改
    * @param  实体
    * @return 操作结果
    */
    @PostMapping("/update")
    public void  update(@RequestBody ${pojo} ${pojo?replace("Tb","")?lower_case}){
        try {
            ${pojo?replace("Tb","")?lower_case}Service.update(${pojo?replace("Tb","")?lower_case});
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
    * 根据主键数组批量删除
    * @param ids 主键数组
    * @return 实体
    */
    @GetMapping("/delete")
    public void delete(String[] ids){
        try {
            ${pojo?replace("Tb","")?lower_case}Service;.deleteByIds(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
    * 根据条件搜索
    * @param pageNum 页号
    * @param pageSize 页面大小
    * @param  搜索条件
    * @return 分页信息
    */
    @PostMapping("/search")
    public PageInfo<${pojo}> search(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
        @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
        @RequestBody ${pojo} ${pojo?replace("Tb","")?lower_case}) {
        return ${pojo?replace("Tb","")?lower_case}Service.search(pageNum, pageSize, ${pojo?replace("Tb","")?lower_case});
    }

}
